//index.js
//获取应用实例
const app = getApp()

Page({
  data: {
    height: app.globalData.height,
    width: app.globalData.width,
    barHeight: app.globalData.barHeight,
    serverUrl: app.globalData.serverUrl,
    uid: wx.getStorageSync('uid'),
    images:[],
    item:[]
  },

  //事件处理函数
  onLoad(options) {
    var item = JSON.parse(options.item)
    var images = item.paths;
    for (var index in images) {
      images[index] = this.data.serverUrl + images[index]
    }
    this.setData({
      item: item,
      images: images
    })
  },
  //返回
  back: function (e) {
    wx.navigateBack({
      delta: 1,
    })
  },

  handleImagePreview(e) {
    var idx = e.target.dataset.idx
    var images = this.data.images
    wx.previewImage({
      current: images[idx],  //当前预览的图片
      urls: images,  //所有要预览的图片
    })
  },

  copyp(e) {
    wx.setClipboardData({
      data: this.data.item.phone,
      success: function (res) {
        wx.showToast({
          title: '已复制',
          icon: "none",
          duration: 800,
        })
      },
      fail: function (res) {
        wx.showToast({
          title: '抱歉，复制失败！',
          icon: "none",
          duration: 800,
        })
      }
    })
  },

  copyw(e) {
    wx.setClipboardData({
      data: this.data.item.weChat,
      success: function (res) {
        wx.showToast({
          title: '已复制',
          icon: "none",
          duration: 800,
        })
      },
      fail: function (res) {
        wx.showToast({
          title: '抱歉，复制失败！',
          icon: "none",
          duration: 800,
        })
      }
    })
  },

  done(e) {
    var that = this;
    wx.showModal({
      title: '确认完成？',
      content: '完成后将隐藏个人信息',
      success(res) {
        if(res.confirm){
          wx.request({
            url: app.globalData.serverUrl + '/admin/sale/donesale',
            method: 'POST',
            data: {
              token: wx.getStorageSync('token'),
              id: that.data.item.id
            },
            success(res) {
              if (res.data.code == 1) {
                wx.showToast({
                  title: '确认成功',
                  icon: "success",
                  duration: 800,
                })
                wx.navigateBack({
                  delta: 1
                })
              } else {
                wx.showToast({
                  title: '确认失败',
                  icon: "fali",
                  duration: 800,
                })
              }
            }
          })
        }
        
      }
    })
  },

  del(e) {
    var that = this;
    wx.showModal({
      title: '确认删除?',
      content: '删除后将不可恢复',
      confirmColor: '#f7635b',
      success(res) {
        if(res.confirm){
          wx.request({
            url: app.globalData.serverUrl + '/admin/sale/delsale',
            method: 'POST',
            data: {
              token: wx.getStorageSync('token'),
              id: that.data.item.id
            },
            success(res) {
              if (res.data.code == 1) {
                wx.showToast({
                  title: '删除成功',
                  icon: "success",
                  duration: 800,
                })
                wx.navigateBack({
                  delta: 1
                })
              } else {
                wx.showToast({
                  title: '删除失败',
                  icon: "fali",
                  duration: 800,
                })
              }
            }
          })
        }
        
      }
    })
  }

})
